package org.hydrakyoufeng.stuplatform.controller;


import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.hydrakyoufeng.stuplatform.dto.*;
import org.hydrakyoufeng.stuplatform.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("class")
@Tag(name = "班级")
public class ClassController {

    @Autowired
    private ClassService classService;

    @PostMapping("queryList")
    public ResponseEntity queryList(@RequestBody ClassListDTO classListDTO) throws Exception  {
        return ResponseEntity.ok(classService.queryList(classListDTO));
    }

    @PostMapping("insert")
    public ResponseEntity insert(@RequestBody ClassDTO classDTO) throws Exception  {
        return ResponseEntity.ok(classService.insert(classDTO));
    }

    @PostMapping("update")
    public ResponseEntity update(@RequestBody ClassDTO classDTO) throws Exception  {
        return ResponseEntity.ok(classService.update(classDTO));
    }

    @DeleteMapping("delete/{id}")
    public ResponseEntity delete(@PathVariable("id") Integer id) throws Exception  {
        return ResponseEntity.ok(classService.delete(id));
    }

    /**
     * 给指定的班级分配课程
     * @param classCourseDTO
     * @return
     * @throws Exception
     */
    @PostMapping("updateCourse")
    public ResponseEntity updateCourse(@RequestBody ClassCourseDTO classCourseDTO) throws Exception  {
        return ResponseEntity.ok(classService.updateCourse(classCourseDTO));
    }

    /**
     * 前端查询可以申请入班的班级列表
     * @param classEntryListDTO
     * @return
     * @throws Exception
     */
    @PostMapping("queryEntryList")
    public ResponseEntity queryEntryList(@RequestBody ClassEntryListDTO classEntryListDTO) throws Exception  {
        return ResponseEntity.ok(classService.queryEntryList(classEntryListDTO));
    }

    /**
     * 申请加入班级
     * @param classUserDTO
     * @return
     * @throws Exception
     */
    @PostMapping("entry")
    public ResponseEntity entry(@RequestBody ClassEntryDTO classUserDTO) throws Exception  {
        return ResponseEntity.ok(classService.entry(classUserDTO));
    }

    /**
     * 查询入班审核列表
     * @param classCheckListDTO
     * @return
     * @throws Exception
     */
    @PostMapping("queryCheckList")
    public ResponseEntity queryCheckList(@RequestBody ClassCheckListDTO classCheckListDTO) throws Exception  {
        return ResponseEntity.ok(classService.queryCheckList(classCheckListDTO));
    }

    /**
     * 入班审核
     * @param classCheckDTO
     * @return
     * @throws Exception
     */
    @PostMapping("check")
    public ResponseEntity check(@RequestBody @Valid ClassCheckDTO classCheckDTO) throws Exception  {
        return ResponseEntity.ok(classService.check(classCheckDTO));
    }

    /**
     * 前端查询用户的班级列表：不分页
     * @return
     * @throws Exception
     */
    @GetMapping("queryUserList")
    public ResponseEntity queryUserList() throws Exception  {
        return ResponseEntity.ok(classService.queryUserList());
    }
}
